/*************************************************************************
	> File Name: 011.P1060.开心的金明.cpp
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 二  6/29 15:03:09 2021
 ************************************************************************/

#include <iostream>
using namespace std;


int n, m, v[25], p[25], w[25], dp[30000];

int main() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> v[i] >> p[i];
        w[i] = v[i] * p[i];
    }

    for (int i = 1; i <= m; i++) {
        for (int j = n; j >= v[i]; j--) {
            dp[j] = max(dp[j], dp[j - v[i]] + w[i]);
        }
    }

    cout << dp[n] << endl;

    return 0;
}
